home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.2)
-
- '''General client side utilities.
-
- This module contains utility functions, used primarily by advanced COM
- programmers, or other COM modules.
- '''
- import pythoncom
- from win32com.client import Dispatch
- PyIDispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]
-
- def WrapEnum(ob, resultCLSID = None):
- '''Wrap an object in a VARIANT enumerator.
-
- \tAll VT_DISPATCHs returned by the enumerator are converted to wrapper objects
- \t(which may be either a class instance, or a dynamic.Dispatch type object).
-
- \t'''
- if type(ob) != pythoncom.TypeIIDs[pythoncom.IID_IEnumVARIANT]:
- ob = ob.QueryInterface(pythoncom.IID_IEnumVARIANT)
-
- return EnumVARIANT(ob, resultCLSID)
-
-
- class Enumerator:
- '''A class that provides indexed access into an Enumerator
-
- \tBy wrapping a PyIEnum* object in this class, you can perform
- \tnatural looping and indexing into the Enumerator.
-
- \tLooping is very efficient, but it should be noted that although random
- \taccess is supported, the underlying object is still an enumerator, so
- \tthis will force many reset-and-seek operations to find the requested index.
-
- \t'''
-
- def __init__(self, enum):
- self._oleobj_ = enum
- self.index = -1
-
-
- def __getitem__(self, index):
- return self._Enumerator__GetIndex(index)
-
-
- def __call__(self, index):
- return self._Enumerator__GetIndex(index)
-
-
- def __GetIndex(self, index):
- if type(index) != type(0):
- raise TypeError, 'Only integer indexes are supported for enumerators'
-
- if index != self.index + 1:
- self._oleobj_.Reset()
- if index:
- self._oleobj_.Skip(index)
-
-
- self.index = index
- result = self._oleobj_.Next(1)
- if len(result):
- return self._make_retval_(result[0])
-
- raise IndexError, 'list index out of range'
-
-
- def Next(self, count = 1):
- ret = self._oleobj_.Next(count)
- if ret is None:
- return None
-
- realRets = []
- for r in ret:
- realRets.append(self._make_retval_(r))
-
- return tuple(realRets)
-
-
- def Reset(self):
- return self._oleobj_.Reset()
-
-
- def Clone(self):
- return self.__class__(self._oleobj_.Clone(), self.resultCLSID)
-
-
- def _make_retval_(self, result):
- return result
-
-
-
- class EnumVARIANT(Enumerator):
-
- def __init__(self, enum, resultCLSID = None):
- self.resultCLSID = resultCLSID
- Enumerator.__init__(self, enum)
-
-
- def _make_retval_(self, result):
- if type(result) == PyIDispatchType:
- result = Dispatch(result, resultCLSID = self.resultCLSID)
-
- return result
-
-
-